//
//  HWRechargeVIPViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/2/14.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWRechargeVIPViewController.h"
#import "HWRechargePackageView.h"
#import "HWRechargeVipHeadView.h"

@interface HWRechargeVIPViewController ()
@property (nonatomic, copy)NSArray *iconArr;
@property (nonatomic, strong)HWRechargePackageView *packageView;
@property (nonatomic, strong)HWRechargeVipHeadView *vipHeadView;
@end

@implementation HWRechargeVIPViewController

- (NSArray *)iconArr
{
    if (!_iconArr)
    {
        _iconArr = @[@{@"title":@"海量嗨书免费读",@"image":@"hibook_freeread"},
                     @{@"title":@"书币8折购",@"image":@"coin_discount"},
                     @{@"title":@"享尊贵标识",@"image":@"honorable_label"},
                     @{@"title":@"敬请期待",@"image":@"please_wait"}];
    }
    return _iconArr;
}

- (HWRechargeVipHeadView *)vipHeadView
{
    if (!_vipHeadView)
    {
        _vipHeadView = [[HWRechargeVipHeadView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,173*kUIScaleBasePlus) vipServiceArr:self.iconArr];
        _vipHeadView.backgroundColor = [UIColor whiteColor];
    }
    return _vipHeadView;
}

- (HWRechargePackageView *)packageView
{
    if (!_packageView)
    {
        _packageView = [[HWRechargePackageView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.vipHeadView.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH,SCREEN_HEIGHT-CGRectGetMaxY(self.vipHeadView.frame)-10*kUIScaleBasePlus)];
        _packageView.backgroundColor = [UIColor whiteColor];
        WeakSelf(self)
        _packageView.paySuccessBlock = ^{
            [weakSelf reloadHead];
        };
    }
    return _packageView;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setTitle:@"充值嗨读VIP"];
    [self setDefaultNav];
    [self buryPoint];
    [self hidePay];
    [self getInfor];
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    [self.view addSubview:self.vipHeadView];
    [self.view addSubview:self.packageView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}

#pragma mark - 获取充值信息
- (void)getInfor
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token
                               };
    
    WeakSelf(self)
    [MyInfoManager getVip:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        HWRechargeVIPModel *model = [[HWRechargeVIPModel alloc]initWithDic:acceptData];
        [weakSelf.vipHeadView getInfo:model];
        [weakSelf.packageView getRechargeDate:model];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取充值信息失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
}

- (void)reloadHead
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token
                               };
    
    WeakSelf(self)
    [MyInfoManager getVip:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        HWRechargeVIPModel *model = [[HWRechargeVIPModel alloc]initWithDic:acceptData];
        [weakSelf.vipHeadView getInfo:model];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取充值信息失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/readVip"
                               fromId:nil
                                 toId:@"0924867f882c8618"];
}


- (void)hidePay
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token                               };
    
    WeakSelf(self)
    [MyInfoManager hidePay:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        [weakSelf.packageView hideWexiOrAliPay:[acceptData stringValue]];
    } fail:^(NSError * _Nullable error) {
        
    }];
}
@end
